package com.sixth.service.impl;

import com.github.pagehelper.util.StringUtil;
import com.sixth.annotation.PageInfoAdvice;
import com.sixth.bean.MarketSearchHistory;
import com.sixth.bean.MarketSearchHistoryExample;
import com.sixth.bean.common.BasePageInfo;
import com.sixth.mapper.MarketSearchHistoryMapper;
import com.sixth.service.AdminHistoryService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @ClassName AdminHistoryServiceImpl
 * @Description TODO
 * @Author XiaoWJ
 * @Date 2022/9/7 20:17
 **/
@Service
public class AdminHistoryServiceImpl implements AdminHistoryService {

    @Autowired
    MarketSearchHistoryMapper marketSearchHistoryMapper;

    @PageInfoAdvice
    @Override
    public Object list(BasePageInfo basePageInfo, Integer userId, String keyword) {
        MarketSearchHistoryExample example = new MarketSearchHistoryExample();

        MarketSearchHistoryExample.Criteria criteria = example.createCriteria();

        if (!StringUtil.isEmpty(keyword)) {
            criteria.andKeywordLike("%" + keyword.trim() + "%");
        }

        if (userId != null) {
            criteria.andUserIdEqualTo(userId);
        }

        example.setOrderByClause(basePageInfo.getSort() + " " + basePageInfo.getOrder());

        Object marketSearchHistories = marketSearchHistoryMapper.selectByExample(example);
        return marketSearchHistories;
    }
}
